<?php

/**
 *
 * @copyright	Copyright 2009-2012   庆丰裕软件工作室
 * @author	Zheng HanWei <315933614@qq.com
 * @link	http://www.qfyu.net/
 *  
 * */
if ($_POST['videoadd']) {

    function converttoflv($in, $out) {

        $cmd = "e:/ffmpeg/bin/ffmpeg.exe -v 0 -i $in -ar 11025 $out 2>&1";
        $fh = popen($cmd, "r");
        while (fgets($fh)) {
            
        }
        pclose($fh);
    }

    function getthumbnail($in, $out) {

        $cmd = "e:/ffmpeg/bin/ffmpeg.exe -i $in -pix_fmt rgb24 -ss 1 -vframes 1 -s 300x200 $out 2>&1";
        $fh = popen($cmd, "r");
        while (fgets($fh)) {
            
        }
        pclose($fh);
    }

    function flv_import($upfile, $fname, $title) {
        
        $fname = preg_replace( '/\.[^\.]+$/','', basename( $fname ) ); 
        $flvpath = "$fname.flv";
        $thumbpath = "$fname.gif";

        converttoflv($upfile, "movies/$flvpath");
        getthumbnail($upfile, "movies/$thumbpath");

       $sql="insert into ".TRAINVID." (title,source,cat,cats,smalltext,price,detail,thumb,width,height)
                values('$title','$flvpath','$_POST[cat]','$_POST[cats]','$_POST[smalltext]','$_POST[price]','$_POST[detail]','$thumbpath',300,200)";
       mysql_query($sql);
    }

    $import=flv_import($_FILES['video']['tmp_name'], $_FILES['video']['name'], $_POST['title']);
    if($import){
        
    }
}
$sql="select * from ".TRAINCAT." where fid=0";
$db->query($sql);
$tcat=$db->getRows();


$tpl->assign("tcat",$tcat);
$tpl->assign("config",$config);
$tpl->assign("lang",$lang);
$output=tplfetch("admin_train_add.htm")
?>
